from time import sleep

from selenium import  webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.support.wait import WebDriverWait  # 显示等待
from selenium.webdriver.support import  expected_conditions#   #判断条件模块
from selenium.webdriver.support.select import Select    # 下拉框模块
class LoginPage(BasePage):
    def __init__(self,driver):
        super().__init__(driver)
        #
        self.account_loc ="xpath,//input[@id='account']"
        self.password_loc = "xpath,//input[@id='password']"
        self.submit_loc = "xpath, //button[@id='submit']"
        self.aasert_text_loc = "xpath,/html/body/div[2]/div/div/div[1]/div"
    def type_account(self,username):
        self.input(self.account_loc,username)

    def type_password(self,password):
        self.input(self.password_loc,password)

    def type_submit(self):
        self.click(self.submit_loc)

    # 返回登录失败 文本，作为断言失败的
    def assert_text(self):
        return self.get_text(self.aasert_text_loc)
    # 登录流程
    def test_login(self,username="admin",password="123456",expect="登录失败，请检查您的成员名或密码是否填写正确。"):
        self.open("http://localhost/ranzhi/www/" ,5)
        self.type_account(username)
        self.type_password(password)
        self.type_submit()
        self.wait(1)
        # print(self.assert_text())
        assert self.assert_text() == expect
        self.quit()

if __name__ == '__main__':
    driver = webdriver.Chrome()
    login = LoginPage(driver)
    login.test_login()